﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace MISAPP.Classify.DataAccess
{
    public class DA_KPI:DA_Matrix
    {
        public DA_KPI()
        {
            tableName = "Presentation";
        }

        public bool Insert(string p_fileName,string p_user,string p_team)
        {
            FillTableSchema(tableName);
            whereList = new List<string>();
            fieldList = new List<field>();
            string sql = @"
INSERT INTO Presentation(MISGroup,init_time,PPT,PPTCount,user_id)
VALUES(@p_team,GETDATE(),@p_fileName,0,@p_user)
";
            FillFieldList(new string[] { p_team }, new string[] { "@p_team" }, "MISGroup");
            FillFieldList(new string[] { p_fileName }, new string[] { "@p_fileName" }, "PPT");
            FillFieldList(new string[] { p_user }, new string[] { "@p_user" }, "user_id");
            AddParameter(sql);
            int iResult = Common.DAL.ExecuteNoneQuery(cmd);
            return iResult < 0 ? false : true;   
        }

        public DataTable GetData()
        {
            string sql = @"
SELECT 
	*
FROM(
	SELECT 
	    A.MISGroup
	    ,A.user_id
	    ,A.PPT
	    ,ROW_NUMBER() OVER(PARTITION BY A.MISGroup ORDER BY A.INIT_Time DESC) AS SEQ
	FROM Presentation A
    WHERE PPTCount = 0
)A
WHERE A.SEQ = 1
";
            return getData(sql, "KPI");
        }

        public DataTable GetSquaredAreaByLevel(string p_level)
        {
            return getSquaredAreaByLevel("KPI", p_level);
        }
    }
}
